home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 1 / your choice.zip / your choice / PRGMMING / MOUDESIG / MDEMO1.BAS < prev    next >
BASIC Source File  |  1993-04-20  |  13KB  |  403 lines

  1. '≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  2. '
  3. '                             Mouse Design 1.0
  4. '                                MouseDEMO 1
  5. '
  6. '               How to use mouse control in QuickBASIC 4.50
  7. '
  8. '                   Written in 1993 by Rudi Breedenraedt
  9. '                               PUBLIC DOMAIN
  10. '
  11. ' This program is a part of the Mouse Design package and is a simple demon-
  12. ' stration of how to use mouse control in your software. This program (not
  13. ' the other programs of the Mouse Design package) is public domain, so you
  14. ' may use the routines of this program into your own software.
  15. '
  16. '≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  17.  
  18. DECLARE FUNCTION mouse.present% ()
  19. DECLARE FUNCTION mouse.buttons% ()
  20. DECLARE SUB mouse.hide ()
  21. DECLARE SUB mouse.show ()
  22. DECLARE SUB mouse.where (x%, y%, b%)
  23. DECLARE SUB mouse.lastpressed (b%, x%, y%, times%)
  24. DECLARE SUB mouse.lastreleased (b%, x%, y%, times%)
  25. DECLARE SUB mouse.window (x1%, y1%, x2%, y2%)
  26. DECLARE FUNCTION using$ (format$, number%)
  27. DECLARE SUB box (y%, x%, l%, h%, t%)
  28. DECLARE SUB mainscreen ()
  29. DECLARE SUB update.lastpressed ()
  30. DECLARE SUB update.area ()
  31. DECLARE SUB update.visibility ()
  32.  
  33. '============================================================================
  34. ' Necessary to call interrupts :
  35. '============================================================================
  36.  
  37. '$INCLUDE: 'qb.bi'
  38. DIM SHARED Reg AS RegType
  39.  
  40. '============================================================================
  41. ' Is there a mouse ? If no, quit with errormessage :
  42. '============================================================================
  43.  
  44. IF NOT mouse.present% THEN
  45.    PRINT "Microsoft mouse not found."
  46.    END
  47.    END IF
  48.  
  49. '============================================================================
  50. ' Initialising :
  51. '============================================================================
  52.  
  53. DIM F1 AS STRING * 2
  54. DIM F2 AS STRING * 2
  55. DIM F3 AS STRING * 2
  56.   F1 = CHR$(0) + ";"
  57.   F2 = CHR$(0) + "<"
  58.   F3 = CHR$(0) + "="
  59. CALL mainscreen
  60. 'Initialising vars:
  61. buttons% = mouse.buttons%
  62. hidden% = 0
  63. lplx% = 0
  64. lply% = 0
  65. lprx% = 0
  66. lpry% = 0
  67. times% = 0
  68. area$ = "Unlock"
  69. visi$ = "ON"
  70. buttons% = mouse.buttons%
  71. mouse.window 32, 2, 79, 24
  72. mouse.show
  73.  
  74. '============================================================================
  75. ' Main loop of the program: update the data on the screen and look if
  76. ' functionkeys are pressed :
  77. '============================================================================
  78. LOCATE 3, 19: PRINT using$("0", buttons%)
  79. LOCATE 10, 24: PRINT using$("00", 1)
  80. LOCATE 11, 24: PRINT using$("00", 1)
  81. LOCATE 12, 24: PRINT using$("00", 1)
  82. LOCATE 13, 24: PRINT using$("00", 1)
  83. LOCATE 18, 16: PRINT "Unlocked"
  84. LOCATE 23, 22: PRINT "Visible"
  85.  
  86. DO
  87.   k$ = INKEY$
  88.   mouse.where x%, y%, b%
  89.   LOCATE 4, 11: PRINT using$("00", x%)
  90.   LOCATE 5, 11: PRINT using$("00", y%)
  91.   LOCATE 6, 20
  92.   SELECT CASE b%
  93.     CASE 0
  94.       PRINT "None      "
  95.     CASE 1
  96.       PRINT "Left      "
  97.     CASE 2
  98.       PRINT "Right     "
  99.     CASE 3
  100.       PRINT "Left+Right"
  101.     CASE 4
  102.       PRINT "Middle    "
  103.     CASE 5
  104.       PRINT "Left+Midd."
  105.     CASE 6
  106.       PRINT "Right+Mid."
  107.     CASE 7
  108.       PRINT "All       "
  109.   END SELECT
  110.   IF k$ = F1 THEN CALL update.lastpressed
  111.   IF k$ = F2 THEN : CALL update.area
  112.   IF k$ = F3 THEN : CALL update.visibility
  113. LOOP UNTIL k$ = CHR$(27)
  114.  
  115. '============================================================================
  116. ' End of the demo :
  117. '============================================================================
  118.  
  119. Reg.ax = 0                 'This interruptcall resets the
  120. INTERRUPT &H33, Reg, Reg   'mouse driver.
  121. COLOR 7, 0
  122. CLS
  123. END
  124.  
  125. SUB box (y%, x%, l%, h%, t%)
  126. ' Draws a box with lines where x and y gives the left top corner,
  127. ' l the length, h the hight and t the form as :
  128. '  t = 0 : draw box with spaces
  129. '  t = 1 : draw box with ┌,─,┘,│,┐ and └
  130. '  t = 2 : draw box with ╔,═,╝,║,╗ and ╚
  131. '  t = 3 : draw box with ▀,▄ and █.
  132. ' l and h may not be less than two and the box must match
  133. ' with the screen coordinates, else no box will be drawn.
  134. ' Note : the box will be drawn in the actual color attributes.
  135.  
  136. DIM lines(1 TO 7) AS STRING * 1
  137. DIM curx, cury AS INTEGER
  138. IF l% < 2 OR h% < 2 THEN EXIT SUB
  139. IF (x% = l%) > 81 OR (y% + h%) > 26 THEN EXIT SUB
  140. curx = POS(0): cury = CSRLIN
  141. IF t% = 0 THEN
  142.    lines(1) = " "
  143.    lines(2) = " "
  144.    lines(3) = " "
  145.    lines(4) = " "
  146.    lines(5) = " "
  147.    lines(6) = " "
  148.    lines(7) = " "
  149.    END IF
  150. IF t% = 1 THEN
  151.    lines(1) = "┌"
  152.    lines(2) = "┘"
  153.    lines(3) = "┐"
  154.    lines(4) = "└"
  155.    lines(5) = "│"
  156.    lines(6) = "─"
  157.    lines(7) = "─"
  158.    END IF
  159. IF t% = 2 THEN
  160.    lines(1) = "╔"
  161.    lines(2) = "╝"
  162.    lines(3) = "╗"
  163.    lines(4) = "╚"
  164.    lines(5) = "║"
  165.    lines(6) = "═"
  166.    lines(7) = "═"
  167.    END IF
  168. IF t% = 3 THEN
  169.    lines(1) = "█"
  170.    lines(2) = "█"
  171.    lines(3) = "█"
  172.    lines(4) = "█"
  173.    lines(5) = "█"
  174.    lines(6) = "▀"
  175.    lines(7) = "▄"
  176.    END IF
  177. LOCATE y%, x%: PRINT lines(1); STRING$(l% - 2, lines(6)); lines(3);
  178. FOR n% = y% + 1 TO y% + h% - 2
  179.     LOCATE n%, x%: PRINT lines(5); STRING$(l% - 2, 32); lines(5);
  180. NEXT n%
  181. LOCATE y% + h% - 1, x%: PRINT lines(4); STRING$(l% - 2, lines(7)); lines(2);
  182. LOCATE cury, curx
  183. END SUB
  184.  
  185. SUB mainscreen
  186. COLOR 7, 0
  187. CLS
  188. COLOR 15, 1
  189. box 1, 1, 30, 7, 2
  190. box 8, 1, 30, 8, 1
  191. box 16, 1, 30, 5, 1
  192. box 21, 1, 30, 5, 1
  193. COLOR 4, 0
  194. box 1, 31, 50, 25, 3
  195. COLOR 8
  196. FOR n = 1 TO 6
  197.   LOCATE 16 + n, 60: PRINT STRING$(15, 219);
  198. NEXT n
  199. COLOR 14, 0
  200. LOCATE 3, 45: PRINT "Mouse Design : MDEMO1"
  201. LOCATE 4, 42: PRINT "Mouse control in QuickBASIC"
  202. COLOR 15, 1
  203. LOCATE 1, 3: PRINT "▌PRESENT MOUSE STATUS▐"
  204. LOCATE 8, 3: PRINT "▌LAST PRESSED WHERE▐"
  205. LOCATE 16, 3: PRINT "▌AREA▐"
  206. LOCATE 21, 3: PRINT "▌VISIBILITY▐"
  207.  
  208. LOCATE 3, 3: PRINT "Nbr of buttons:"
  209. LOCATE 4, 3: PRINT "X-axis:"
  210. LOCATE 5, 3: PRINT "Y-axis:"
  211. LOCATE 6, 3: PRINT "Pressed buttons:"
  212. LOCATE 10, 3: PRINT "Lastpressed left: X:"
  213. LOCATE 11, 3: PRINT "                  Y:"
  214. LOCATE 12, 3: PRINT "           right: X:"
  215. LOCATE 13, 3: PRINT "                  Y:"
  216. LOCATE 18, 3: PRINT "Area status:"
  217. LOCATE 23, 3: PRINT "Visibility status:"
  218.  
  219. COLOR 9, 1
  220. LOCATE 14, 3: PRINT "F1 TO UPDATE"
  221. LOCATE 19, 3: PRINT "F2 TO TOGLE LOCK/UNLOCK"
  222. LOCATE 24, 3: PRINT "F3 TO TOGLE ON/OFF";
  223. COLOR 7, 1
  224. END SUB
  225.  
  226. '----------------------------------------------------------------------------
  227. ' This function returns the number of buttons on the mouse (2 or 3).
  228. ' IMPORTANT NOTE: this function also resets the mouse driver, so after
  229. '   executing this function, the mouse will be hidden and the mouse
  230. '   window will be reset to the whole screen !
  231. '----------------------------------------------------------------------------
  232. FUNCTION mouse.buttons%
  233. Reg.ax = 0
  234. INTERRUPT &H33, Reg, Reg
  235. IF Reg.bx = -1 THEN Reg.bx = 2
  236. mouse.buttons% = Reg.bx
  237. END FUNCTION
  238.  
  239. '----------------------------------------------------------------------------
  240. ' This routine makes the mouse cursor invisible. The mouse cursor can
  241. ' be made visible again with the subroutine mouse.show.
  242. ' IMPORTANT NOTE: multiple calls of this subroutine will require multiple
  243. '   calls of the subroutine mouse.show to unhide the mouse cursor !
  244. '----------------------------------------------------------------------------
  245. SUB mouse.hide
  246. Reg.ax = 2
  247. INTERRUPT &H33, Reg, Reg
  248. END SUB
  249.  
  250. '----------------------------------------------------------------------------
  251. ' Specify with b% which button to check (1=left, 2=right, 3=middle), this
  252. ' routine will then return the x and y coordinates where this mouse button
  253. ' was last pressed. The variable times% will tell you how many times the
  254. ' specified button was pressed since you called this routine last.
  255. ' IMPORTANT NOTE: This subroutine should be modified for use in a graphical
  256. '   environment because of the difference in screen resolution !
  257. '----------------------------------------------------------------------------
  258. SUB mouse.lastpressed (b%, x%, y%, times%)
  259. Reg.ax = 5
  260. Reg.bx = b% - 1
  261. INTERRUPT &H33, Reg, Reg
  262. times% = Reg.bx
  263. x% = Reg.cx \ 8 + 1
  264. y% = Reg.dx \ 8 + 1
  265. END SUB
  266.  
  267. '----------------------------------------------------------------------------
  268. ' Specify with b% which button to check (1=left, 2=right, 3=middle), this
  269. ' routine will then return the x and y coordinates where this mouse button
  270. ' was last released. The variable times% will tell you how many times the
  271. ' specified button was released since you called this routine last.
  272. ' IMPORTANT NOTE: This subroutine should be modified for use in a graphical
  273. '   environment because of the difference in screen resolution !
  274. '----------------------------------------------------------------------------
  275. SUB mouse.lastreleased (b%, x%, y%, times%)
  276. Reg.ax = 6
  277. Reg.bx = b% - 1
  278. INTERRUPT &H33, Reg, Reg
  279. times% = Reg.bx
  280. x% = Reg.cx \ 8 + 1
  281. y% = Reg.dx \ 8 + 1
  282. END SUB
  283.  
  284. '----------------------------------------------------------------------------
  285. ' This routine makes it possible to locate the mouse cursor on a specified
  286. ' location on the screen.
  287. ' IMPORTANT NOTE: This subroutine should be modified for use in a graphical
  288. '   environment because of the difference in screen resolution !
  289. '----------------------------------------------------------------------------
  290. SUB mouse.locate (x%, y%)
  291. Reg.ax = 4
  292. Reg.cx = (x% - 1) * 8
  293. Reg.dx = (y% - 1) * 8
  294. INTERRUPT &H33, Reg, Reg
  295. END SUB
  296.  
  297. '----------------------------------------------------------------------------
  298. ' This function returns 0 if there is no mouse connected, or if the
  299. ' mouse driver MOUSE.COM is not loaded. Else the function returns -1.
  300. ' When you begin a mouse controlled program you should use this function
  301. ' to check if the mouse is present.
  302. ' IMPORTANT NOTE: this function also resets the mouse driver, so after
  303. '   executing this function, the mouse will be hidden and the mouse
  304. '   window will be reset to the whole screen !
  305. '----------------------------------------------------------------------------
  306. FUNCTION mouse.present%
  307. Reg.ax = 0
  308. INTERRUPT &H33, Reg, Reg
  309. mouse.present% = Reg.ax
  310. END FUNCTION
  311.  
  312. '----------------------------------------------------------------------------
  313. ' This routine makes the mouse cursor visible. The mouse cursor can
  314. ' be made invisible with the subroutine mouse.hide.
  315. ' When you begin a mouse controlled program you should use this routine
  316. ' to make the mouse cursor visible.
  317. '----------------------------------------------------------------------------
  318. SUB mouse.show
  319. Reg.ax = 1
  320. INTERRUPT &H33, Reg, Reg
  321. END SUB
  322.  
  323. '----------------------------------------------------------------------------
  324. ' This routine looks where the mouse cursor actually is located, and if
  325. ' there are buttons pressed. The variable b% returns 0 of no button is
  326. ' pressed, 1 if the left one is pressed, 2 if the right, 3 if both left
  327. ' and right are pressed. It adds 4 to this value if the middle button is
  328. ' pressed.
  329. ' IMPORTANT NOTE: This subroutine should be modified for use in a graphical
  330. '   environment because of the difference in screen resolution !
  331. '----------------------------------------------------------------------------
  332. SUB mouse.where (x%, y%, b%)
  333. Reg.ax = 3
  334. INTERRUPT &H33, Reg, Reg
  335. b% = Reg.bx
  336. x% = Reg.cx \ 8 + 1
  337. y% = Reg.dx \ 8 + 1
  338. END SUB
  339.  
  340. '----------------------------------------------------------------------------
  341. ' This routine makes it possible to lock the mouse cursor in a specified
  342. ' rectangular block with x1%,y1% as coordinates of the upper left corner,
  343. ' and x2%,y2% as coordinates of the lower right corner.
  344. ' To unlock the mouse, call this routine back again with the coordinates
  345. ' of the whole screen.
  346. ' IMPORTANT NOTE: This subroutine should be modified for use in a graphical
  347. '   environment because of the difference in screen resolution !
  348. '----------------------------------------------------------------------------
  349. SUB mouse.window (x1%, y1%, x2%, y2%)
  350. Reg.ax = 7
  351. Reg.cx = (x1% - 1) * 8
  352. Reg.dx = (x2% - 1) * 8
  353. INTERRUPT &H33, Reg, Reg
  354. Reg.ax = 8
  355. Reg.cx = (y1% - 1) * 8
  356. Reg.dx = (y2% - 1) * 8
  357. INTERRUPT &H33, Reg, Reg
  358. END SUB
  359.  
  360. SUB update.area
  361. STATIC status$
  362. IF status$ = "" THEN status$ = "Unlocked"
  363. IF status$ = "Unlocked" THEN
  364.    status$ = "Locked  "
  365.    mouse.window 60, 17, 74, 22
  366. ELSE
  367.    status$ = "Unlocked"
  368.    mouse.window 32, 2, 79, 24
  369. END IF
  370. LOCATE 18, 16: PRINT status$
  371. END SUB
  372.  
  373. SUB update.lastpressed
  374. mouse.lastpressed 1, x%, y%, t%
  375. LOCATE 10, 24: PRINT using$("00", x%)
  376. LOCATE 11, 24: PRINT using$("00", y%)
  377. mouse.lastpressed 2, x%, y%, t%
  378. LOCATE 12, 24: PRINT using$("00", x%)
  379. LOCATE 13, 24: PRINT using$("00", y%)
  380. END SUB
  381.  
  382. SUB update.visibility
  383. STATIC status$
  384. IF status$ = "" THEN status$ = "Visible"
  385. IF status$ = "Visible" THEN
  386.    status$ = "Hidden "
  387.    mouse.hide
  388. ELSE
  389.    status$ = "Visible"
  390.    mouse.show
  391. END IF
  392. LOCATE 23, 22: PRINT status$
  393. END SUB
  394.  
  395. FUNCTION using$ (format$, number%)
  396. s$ = RTRIM$(LTRIM$(STR$(number%)))
  397. DO WHILE LEN(s$) < LEN(format$)
  398.   s$ = "0" + s$
  399. LOOP
  400. using$ = s$
  401. END FUNCTION
  402.  
  403.